Declares a variable or an array at the procedure level within a subroutine or a function, so that the values of the variable or the array are retained after exiting the subroutine or function. Dim statement conventions are also valid.
関数およびサブルーチン内で変数や配列を定義する際に、これらをプロシージャーレベルで再利用することを宣言して、該当する関数およびサブルーチンが終了しても、こうした変数や配列に代入した値を保持するようにします。ここでは Dim ステートメントと同様の規約が適用されます。
![]() | The Static statement cannot be used to define variable arrays. Arrays must be specified according to a fixed size.
Static ステートメント は、配列変数の定義には使用できません。配列は固定サイズで定義する必要があります。 |
Static VarName[(start To end)] [As VarType], VarName2[(start To end)] [As VarType], ...
Static VarName[(start To end)] [As VarType], VarName2[(start To end)] [As VarType], ...
Sub ExampleStatic
Sub ExampleStatic
Dim iCount as Integer, iResult as Integer
Dim iCount as Integer, iResult as Integer
For iCount = 0 to 2
For iCount = 0 to 2
iResult = InitVar()
iResult = InitVar()
Next iCount
Next iCount
MsgBox iResult,0,"The answer is"
MsgBox iResult,0,"The answer is"
End Sub
End Sub
REM Function for initialization of the static variable
REM スタティック変数の初期化用関数
Function InitVar() As Integer
Function InitVar() As Integer
Static iInit As Integer
Static iInit As Integer
Const iMinimum as Integer = 40 REM minimum return value of this function
Const iMinimum as Integer = 40 REM minimum return value of this function
if iInit = 0 then REM check if initialized
if iInit = 0 then REM check if initialized
iInit = iMinimum
iInit = iMinimum
else
else
iInit = iInit + 1
iInit = iInit + 1
end if
end if
InitVar = iInit
InitVar = iInit
End Function
End Function